# Patches folder contents to show our import button even if folder has no items.

from Acquisition import aq_inner
from Products.CMFCore.utils import getToolByName

@property
def buttons(self):
    buttons = []
    portal_actions = getToolByName(self.context, 'portal_actions')
    button_actions = portal_actions.listActionInfos(object=aq_inner(self.context),
                                                    categories=('folder_buttons', ))
    # Do not show buttons if there is no data, unless there is data to be
    # pasted
    if not len(self.items):
        for button in button_actions:
            if button['id'] == 'import' or \
                   (button['id'] == 'paste' and self.context.cb_dataValid()):
                buttons.append(self.setbuttonclass(button))
        return buttons
    
    for button in button_actions:
        # Make proper classes for our buttons
        if button['id'] != 'paste' or self.context.cb_dataValid():
            buttons.append(self.setbuttonclass(button))

    return buttons

from plone.app.content.browser.foldercontents import FolderContentsTable
FolderContentsTable.buttons = buttons
    




